import Vue from 'vue';
import Router from 'vue-router'
Vue.use(Router);
const Layout=()=>import('@/views/layout/Layout');

export const constantRoutes = [
  {
    path: '/', component:Layout,
    children: [
      {path: '', component: ()=>import('@/views/front') },
      {path: 'article/:id', component: ()=>import('@/views/front/article/article')},
      {path: 'addArticle', component: ()=>import('@/views/front/article/addArticle')},
      {path: 'project', component: ()=>import('@/views/front/project/project')},
      {path: 'aboutMe', component: ()=>import('@/views/front/aboutMe/aboutMe')},
      {path: 'message/:to', component: ()=>import('@/views/front/message/message')},
      {path: 'center', component: ()=>import('@/views/front/center/center')},
    ],
  },
  {
    name: 'index',
    path: '/cms',
    component: ()=>import('@/views/cms/Home'),
      children: [
        { path: "/articleClass", component:()=>import('@/views/cms/article/class/ArticleClass') },
        { path: "/articleList", component: ()=>import('@/views/cms/article/list/ArticleList') },
        { path: "/comments", component: ()=>import('../views/cms/comments/Comments.vue') },
      ]
  },
  {
    path: '/login', component:Layout,
    children: [
      { path: "", component:()=> import('@/views/Login.vue') },
    ]
  },
];


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
